package com.hx.demo28.controller;

import com.hx.demo28.pojo.BoKe;
import com.hx.demo28.service.BokeService;
import com.hx.demo28.utils.Code;
import com.hx.demo28.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/boke")
@CrossOrigin
public class BokeController {

    @Autowired
    private BokeService bokeService;

    @RequestMapping("/add")
    public Result addById(@RequestBody BoKe boKe){
        int i = bokeService.addfindById(boKe);
        if (i>0){
            return new Result(Code.GET_OK,boKe,"添加成功");
        }else {
            return new Result(Code.GET_ERR,"添加失败");
        }
    }
    @RequestMapping("/find")
    public Result findById(){
        List<BoKe> allBy = bokeService.findAllBy();
        if (allBy!=null){
            return new Result(Code.GET_OK,allBy,"查询成功");

        }else {
            return new Result(Code.GET_ERR,"查询失败");
        }
    }
}
